package com.foreveross.crawl.common.util;

import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.List;

/**
 * SQL语句辅助类
 * @author xiangsf
 * @version $Revision$
 * @since $Date$
 */
public final class SqlUtils {

	
	public static String getInSqlByString(List<String> list){
		if(list == null || list.isEmpty()) return "";
		StringBuilder builder= new StringBuilder();
		for(String s : list){
			builder.append("'").append(s).append("',");
		}
		return builder.substring(0, builder.length()-1).toString();
	}
	
	public static String getInSqlByLong(List<Long> list){
		if(list == null || list.isEmpty()) return "";
		StringBuilder builder= new StringBuilder();
		for(Long s : list){
			builder.append(s).append(",");
		}
		return builder.substring(0, builder.length()-1).toString();
	}
	
	  /**
	   * 格式化oracle日期 ，将一个日期格式化成字符串，形如：to_date('xxx','yyyy-mm-dd hh24:mi:ss')
	   * @param date
	   * @return
	   */
	  public static String formatSqlDay(Date date){
		  String pattern = "yyyy-MM-dd HH:mm:ss";
		  SimpleDateFormat format = new SimpleDateFormat(pattern);
		  String sqlDate="to_date('"+format.format(date)+"','yyyy-mm-dd hh24:mi:ss')";
		  return sqlDate;
	  }
}
